using System;
using System.Windows.Forms;

using Nextensions.Security.Cryptography;

namespace gozer
{
	public partial class Main : Form
	{
		public Main()
		{
			InitializeComponent();
		}

		private void  Encrypt()
		{
			if(!ValidityCheck())
				return;
			
            byte[] encrypted = CryptTool.Encrypt(textInput.Text, textPassphrase.Text);
		}

		private bool ValidityCheck()
		{
			if(textPassphrase.Text != textPassphrase2.Text)
			{
				labelPassphraseErr.Text = "Both pass-phrases must match.";
				labelPassphraseErr.Visible = true;
				return false;
			}
			return true;
		}

		private void Decrypt()
		{
		}

		private void SetButtonStates()
		{
			buttonEncrypt.Enabled =
				(textPassphrase.Text.Length >= CryptTool.MinPassPhraseLength && textPassphrase2.Text.Length >= CryptTool.MinPassPhraseLength && textInput.Text.Length > 0);
			buttonDecrypt.Enabled = textPassphrase.Text.Length >= 8;
		}

		private void  SetPassphraseErrStatus()
		{
			if(textPassphrase.Text == textPassphrase2.Text)
				labelPassphraseErr.Visible = false;
		}

		private void buttonEncrypt_Click(object sender, EventArgs e)
		{
			Encrypt();
		}

		private void buttonDecrypt_Click(object sender, EventArgs e)
		{
			Decrypt();
		}

		private void textPassphrase_TextChanged(object sender, EventArgs e)
		{
			SetPassphraseErrStatus();
			SetButtonStates();
		}

		private void textPassphrase2_TextChanged(object sender, EventArgs e)
		{
			SetButtonStates();
			SetPassphraseErrStatus();
		}

		private void textInput_TextChanged(object sender, EventArgs e)
		{
			SetButtonStates();
		}

		private void Main_Load(object sender, EventArgs e)
		{

		}
	}
}